﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Data.SqlClient;
using System.Configuration;
using Delonix_Regia_Hotel.Class;



namespace Delonix_Regia_Hotel.Class
{
    public class Guest
    {
        private string guestid;
        private string fname;
        private string lname;
        private string ic;
        private string contactnum;
        private string email;
        private string homeaddress;
        private string mailingaddress;
        private string paymethod;
        private string typesofroom;
	private string numofrooms;
        private string cardtype;
        private string cardnum;
        private string expirydate;
        private string periodofstay;
        private string remarks;
        private string roomnum;
        private string dateofarrival;
            private string dateofdeparture;
            private string price;
    

 public Guest()
	{
	}

public Guest(string guestid, string fname,string lname, string ic, string contactnum,string email, 
	    string homeaddress,string mailingaddress, string paymethod,
	     string typesofroom,string numofrooms, string cardtype, string cardnum, string expirydate,
 	     string periodofstay,string remarks, string roomnum,string dateofarrival, string dateofdeparture,string price)
	{
	 this.guestid= guestid;
	 this.fname = fname;
 	 this.lname = lname;
	 this.ic = ic;
	 this.contactnum = contactnum;
	 this.email = email;
	 this.homeaddress = homeaddress;
	 this.mailingaddress = mailingaddress;
	 this.paymethod = paymethod;
	 this.typesofroom = typesofroom;
	 this.numofrooms = numofrooms;
	 this.cardtype = cardtype;
	 this.cardnum = cardnum;
	 this.expirydate = expirydate;
	 this.periodofstay = periodofstay;
	 this.remarks = remarks;
	 this.roomnum = roomnum;
     this.dateofarrival = dateofarrival;
     this.dateofdeparture = dateofdeparture;
     this.price = price;
	}

public string Guestid
{
	get{return guestid;}
	set{guestid= value;}
}
public string Fname
{
	get{return fname ;}
	set{fname =value;}
}	 	
public string Lname
{
	get{return lname ;}
	set{lname =value;}
}

public string Ic
{
	get{return ic ;}
	set{ic =value;}
}
public string Contactnum
{
	get{return contactnum ;}
	set{contactnum =value;}
}
public string Email
{
	get{return email ;}
	set{ email=value;}
}
public string Homeaddress
{
	get{return homeaddress ;}
	set{ homeaddress=value;}
}

public string Mailingaddress
{
	get{return mailingaddress ;}
	set{mailingaddress = value;}
}
public string Paymethod
{
	get{return paymethod;}
	set{paymethod =value;}
}
public string Typesofroom
{
	get{return typesofroom;}
	set{typesofroom =value;}
}
public string Numofrooms
{
	get{return numofrooms ;}
	set{numofrooms =value;}
}
public string Cardtype
{
	get{return cardtype; ;}
	set{cardtype =value;}
}
public string Cardnum
{
	get{return cardnum;}
	set{cardnum =value;}
}
public string Expirydate
{
	get{return expirydate ;}
	set{ expirydate=value;}
}
public string Periodofstay
{
	get{return periodofstay ;}
	set{periodofstay =value;}
}
public string Remarks
{
	get{return remarks ;}
	set{ remarks=value;}
}

public string Roomnum
{
	get{return roomnum;}
    set { roomnum = value; }
}
public string Dateofarrival
{
    get { return dateofarrival; }
    set { dateofarrival = value; }

}
public string DateofDeparture
{
    get { return dateofdeparture; }
    set { dateofdeparture = value; }
}
public string Price
{
    get { return price; }
    set { price = value; }
}
public static int CreateGuest(Guest u)
        {
            int rowsinserted = 0;
            SqlConnection conn = null;
            try
            {
                conn = new SqlConnection();
                conn.ConnectionString=" Data source =.;Initial Catalog = Delonix; Integrated Security = true";
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = " INSERT INTO Guest(guestid,fname,lname,ic,contactnum,email,homeaddress,mailingaddress,paymethod,typesofroom,numofrooms,cardtype,cardnum,expirydate,periodofstay,remarks,roomnum)"
                    + " VALUES(@guestid,@fname,@lname,@ic,@contactnum,@email,@homeaddress,@dob,@mailingaddress,@paymethod,@typesofroom,@numofrooms,@cardtype,@cardnum,@expirydate,@periodofstay,@remarks,@roonum)";

                comm.Parameters.AddWithValue("@guestid", u.guestid);
                comm.Parameters.AddWithValue("@fname", u.fname);
                comm.Parameters.AddWithValue("@lname", u.lname);
                comm.Parameters.AddWithValue("@ic" , u.ic);
                comm.Parameters.AddWithValue("@contactnum", u.contactnum);
                comm.Parameters.AddWithValue("@email", u.email);
                comm.Parameters.AddWithValue("@homeaddress", u.homeaddress);
                comm.Parameters.AddWithValue("@mailingaddress", u.mailingaddress);
                comm.Parameters.AddWithValue("@paymethod", u.paymethod);
                comm.Parameters.AddWithValue("@typesofroom", u.typesofroom);
                comm.Parameters.AddWithValue("@numofrooms", u.numofrooms);
                comm.Parameters.AddWithValue("@cardtype", u.cardtype);
                comm.Parameters.AddWithValue("@cardnum", u.cardnum);
                comm.Parameters.AddWithValue("@expirydate", u.expirydate);
                comm.Parameters.AddWithValue("@periodofstay" , u.periodofstay);
                comm.Parameters.AddWithValue("@remarks", u.remarks);
                comm.Parameters.AddWithValue("@roomnum" , u.roomnum);
                rowsinserted = comm.ExecuteNonQuery();
            }

            catch (SqlException e)
            {
                throw e;
            }
            
            conn.Close();
            return rowsinserted;                  
    }




public static ArrayList GetGuestsByic(string ic)
{
    ArrayList result = new ArrayList();
    SqlConnection conn = null;
    try
    {
        conn = new SqlConnection();
        conn.ConnectionString = " Data source =.;Initial Catalog = Delonix; Integrated Security = true";
        conn.Open();
        SqlCommand comm = new SqlCommand();
        comm.Connection = conn;

        comm.CommandText = "SELECT * FROM Guest WHERE ic=@ic";
        comm.Parameters.AddWithValue("@ic", ic);
        SqlDataReader dr = comm.ExecuteReader();
        while (dr.Read())
        {
            Guest m = new Guest();
            m.fname = (string)dr["fname"];
            m.lname = (string)dr["lname"];
            m.dateofarrival = (string)dr["dateofarrival"];
            m.dateofdeparture = (string)dr["dateofdeparture"];
            m.typesofroom = (string)dr["typesofroom"];
            m.periodofstay = (string)dr["periodofstay"];
            m.roomnum = (string)dr["roomnum"];
            m.price = (string)dr["price"];
            result.Add(m);

        }
        dr.Close();
    }
    catch (SqlException e)
    {
        throw e;
    }
    conn.Close();
    return result;
}

public static int DeleteBookingByGuestic(string ic)
{
    int rowsdeleted = 0;

    SqlConnection conn = null;
    try
    {
        conn = new SqlConnection();
        conn.ConnectionString = " Data source =.;Initial Catalog = Delonix; Integrated Security = true";
        conn.Open();
        SqlCommand comm = new SqlCommand();
        comm.Connection = conn;
        comm.CommandText = "DELETE FROM guest WHERE ic=@ic";

        comm.Parameters.AddWithValue("@ic", ic);

        rowsdeleted = comm.ExecuteNonQuery();
    }
    catch (SqlException e)
    {
        throw e;
    }
    conn.Close();
    return rowsdeleted;
}
}
}
